class Solution:
    def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
        satisfied=0
        for i in range(len(customers)):
            if not grumpy[i]:
                satisfied+=customers[i]
        for i in range(X):
            if grumpy[i]:
                satisfied+=customers[i]
        result=satisfied
        for i in range(X,len(customers)):
            if grumpy[i-X]:
                satisfied-=customers[i-X]
            if grumpy[i]:
                satisfied+=customers[i]
            if satisfied>result:
                result=satisfied
        return result

'''
执行用时：
280 ms
, 在所有 Python3 提交中击败了
100.00%
的用户
内存消耗：
16.9 MB
, 在所有 Python3 提交中击败了
44.86%
的用户
'''